#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
const LL MAX=1e18+999;
LL POW(LL a, LL b) {
    LL res=1;
    while (b--)  {
        res*=a;
        if (res>MAX) return -1;
    }
    return res;
}
int main() {
    vector<LL> res;
    for (LL i=1; i<MAX; i*=2) {
        for (LL j=1; i*j<MAX; j*=3) {
            for (LL k=1; i*j*k<MAX; k*=5) {
                if (i*j*k==1) continue;
                res.push_back(i*j*k);
            }
        }
    }
    sort(res.begin(), res.end());
    //for (int i=0; i<res.size(); ++i) cout<<res[i]<<endl;
    int n;
    LL ask;
    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        scanf("%lld", &ask);
        int t=upper_bound(res.begin(), res.end(), ask)-res.begin();
        if (res[t-1]==ask) printf("%lld\n", ask);
        else printf("%lld\n", res[t]);
    }
    return 0;
}
